package com.jerkin.mynlp;

import com.huaban.analysis.jieba.JiebaSegmenter;
import com.huaban.analysis.jieba.SegToken;
import com.mayabot.nlp.common.Lists;
import com.mayabot.nlp.module.summary.KeywordSummary;
import com.mayabot.nlp.module.summary.SentenceSummary;
import com.mayabot.nlp.segment.FluentLexerBuilder;
import com.mayabot.nlp.segment.Lexer;
import com.mayabot.nlp.segment.Lexers;
import com.mayabot.nlp.segment.Nature;
import com.mayabot.nlp.segment.Sentence;
import com.mayabot.nlp.segment.WordTerm;
import com.mayabot.nlp.segment.plugins.customwords.CustomDictionaryPlugin;
import com.mayabot.nlp.segment.plugins.customwords.MemCustomDictionary;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @className:MynlpHelper
 * @author:huhongzhi
 * @createTime:2021/3/15 11:21
 * @version:1.0
 */
public class MynlpHelper {

    public static final List<Nature> natures = Lists.newArrayList(Nature.a,Nature.Ag,Nature.ad,
            Nature.b,Nature.Bg,Nature.c,Nature.d,Nature.Dg,Nature.i,Nature.j,Nature.k,Nature.l,
            Nature.m,Nature.Mg,Nature.o,Nature.p,Nature.q,Nature.r,Nature.x,Nature.q,Nature.mq,
            Nature.xx,Nature.begin,Nature.end,Nature.Tg,Nature.nx,Nature.w,Nature.y,Nature.Yg);


    public static String segemet(String value) {
//        MemCustomDictionary dictionary = new MemCustomDictionary();
//        dictionary.addWord("蘑菇钉");
//        dictionary.rebuild();
//
//        FluentLexerBuilder builder = Lexers.coreBuilder()
//                .withPos()
//                .withNer()
//                .withPersonName();
//
//        builder.with(new CustomDictionaryPlugin(dictionary));

//        Lexer lexer = builder.build().perceptronBuilder()
//                .withPos()
//                .withPersonName()
//                .withNer()
//                .build();
        Sentence sentence = LexerFactory.getInstance().scan(value);
        List<String> result = new ArrayList<>();
        for (WordTerm wordTerm : sentence.toList()) {
            if (!natures.contains(wordTerm.getNature())) {
                result.add(wordTerm.word);
            }
        }

//        KeywordSummary sentenceSummary = new KeywordSummary();
//        List<String> result = LexerFactory.getKeyWordSummary().keyword(value, 5);
//        List<String> result = new ArrayList<>(sentence.toWordList().size());
        return StringUtils.join(result);
    }

    public static void main(String[] args) {


    }
}